<template>
    <div class="container">
        <div class="header">
            <mt-header title="订单"></mt-header>
            <el-tabs v-model="activeName" @tab-click="handleClick"  style="background-color:#fff">
                <el-tab-pane label="全部订单" name="first"></el-tab-pane>
                <el-tab-pane label="待评价" name="second"></el-tab-pane>
                <el-tab-pane label="已评价" name="third"></el-tab-pane>
            </el-tabs>
        </div>
        <div class="orderContainer">
            <div v-for="(item,index) in orderList" :key="index">
                <div class="orderBox" :class="{evalationOrderBox:activeName=='third'}">
                    <div class="message">
                        <img :src="'/file'+item.shopBase.shopUrl">
                        <span @click="gotoShop(item.shopBase.shopid)">{{item.shopBase.shopName}}</span>
                        <span @click="gotoShop(item.shopBase.shopid)" class="link">></span>
                        <span class="right">{{tagList[item.tag]}}</span>
                    </div>
                    <router-link :to="{name:'orderMessage',params:{orderId:item.orderId}}" style="text-decoration: none;">
                        <div class="shopCart">
                            <div class="imgBox">
                                <div v-for="(item_son,i) in item.foodDetails" :key="i" style="display:flex;align-items:center">
                                    <img :src="'/file'+item_son.foodUrl">
                                    <div class="oneFood" v-if="item.foodDetails.length==1">{{item_son.foodName}}</div>
                                </div>
                            </div>
                            <div class="shopMessage">
                                <p class="money">￥{{item.sumCost/100}}</p>
                                <p>共{{item.foodDetails.length}}件</p>
                            </div>
                        </div>
                    </router-link>
                    <button v-if="activeName=='first'">再来一单</button>
                    <button v-if="activeName=='second'" @click="gotoEvaluation(item.orderId)">去评价</button>
                    <p class="evalation" v-if="activeName=='third'">评论：{{'馄饨真好吃！！！'}}</p>
                </div>
            </div>
            <button class="more" v-if="!closeMore" @click="getOrderList">查看更多历史订单</button>
        </div>
        <footer-bar class="footerClass"></footer-bar>
    </div>
</template>
<script>
    import footerBar from '../components/footer';
    import { mapMutations } from "vuex";
    export default({
        data(){
            return{
                img:[1,2,3,4,5],
                orderList:[],
                currentPage:0,
                size:5,
                closeMore:false,
                activeName:'first',
                tagList:{
                    '1':'已送达',
                    '0':'已支付',
                    '-1':'已取消'
                },
            }
        },
        components:{ 
            footerBar,
        },
        mounted(){
            this.getOrderList();
        },
        methods:{
            ...mapMutations(['setShopId']),
            handleClick(){
            },
            gotoEvaluation(orderId){
                this.$router.push({name:'evaluation',params:{'orderId':orderId}});
            },
            gotoShop(shopId){
                console.log(shopId);
                this.setShopId(shopId);
                this.$router.push('shop');
            },
            getOrderList(){
                let tokenStr=window.sessionStorage.getItem('tokenStr');
                this.currentPage=this.currentPage+1;
                let postData={
                    currentPage:this.currentPage,
                    size:this.size
                }
                this.getRequest('/order/getOrderList',postData,tokenStr).then(response=>{
                    if(response.code==200){
                        for(let item in response.obj.data){
                            this.orderList.push(response.obj.data[item]);
                        }
                        if(this.orderList.length==response.obj.total)
                            this.closeMore=true;
                    }
                })
            }
        }
    })
</script>
<style lang="scss" scoped>
    @import 'mint-ui/lib/style.css';
    @import '../style/mixin';
    *{
        margin: 0;
        padding: 0;
    }
    /deep/ .el-tabs__item{
        font-size:18px;
    }
    /deep/ .el-tabs__header{
        margin:0;
    }
    /deep/ .el-tabs__nav{
        padding:0.2rem;
    }
    .container{
        background-color: #f1f1f1;
        margin-top:6rem;
        @include width-height(100%,85vh);
    }
    .header{
        @include width-height(100%,6rem);
        position: fixed;
        top: 0;
        z-index: 999;
    }
    .orderContainer{
        overflow: hidden auto;
        @include width-height(100%,82vh);
        
    }
    .more{
        @include width-height(100%,2.5rem);
        @include font-size-color(1.2rem,#666);
        border: none;
    }
    .evalation{
        padding:0.5rem;
    }
    .evalationOrderBox{
        height:auto !important;
    }
    .orderBox{
        display: flex;
        position: relative;
        @include width-height(100%,11rem);
        border-radius: 0.8rem;
        margin-top: 0.3rem;
        flex-direction: column;
        background-color: #fff;
        .message{
            display: flex;
            padding-left:0.5rem;
            @include width-height(100%,3.5rem);
            align-items: center;
            position: relative;
            img{
                @include width-height(45px,45px);
                border-radius: 0.8rem;
            }
            span{
                padding-left: 0.5rem;
                @include font-size-color(1.3rem,#000);
                font-weight: bold;
            }
            .link{
                @include font-size-color(1.3rem,#666);
            }
            .right{
                position: absolute;
                right:1.5rem;
                @include font-size-color(1rem,#666);
                font-weight: normal;
            }
        }
        .shopCart{
            display: flex;
            @include width-height(100%,4.5rem);
            align-items: center;
            .imgBox{
                display: flex;
                align-items:center;
                @include width-height(75%,4.5rem);
                overflow:auto hidden;
                img{
                    padding-left: 0.5rem;
                    @include width-height(60px,60px);
                }
                .oneFood{
                    @include font-size-color(1.2rem,#000);
                    padding-left:1rem;
                }
            }
            .shopMessage{
                display: flex;
                flex-direction: column;
                align-items: center;
                position: absolute;
                right: 1rem;
                p{
                @include font-size-color(1rem,#666);
                }
                .money{
                    @include font-size-color(1.3rem,#000);
                }
            }
        }
        button{
            @include width-height(6rem,2rem);
            border: #26a2ff;
            @include font-size-color(1.2rem,#26a2ff);
            border:1px solid #26a2ff;
            background-color: #fff;
            border-radius: 1rem;
            position: absolute;
            right: 0.2rem;
            bottom: 1rem;
        }
    }
    .footerClass{
        @include width-height(100%,3rem);
        position: fixed;
        bottom: 0;
    }
</style>